package org.jeecg.modules.PriceSystemModule.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.modules.PriceSystemModule.entity.PriceInervalEntity;
import org.jeecg.modules.PriceSystemModule.entity.PriceSystemEntity;
import org.jeecg.modules.PriceSystemModule.mapper.PriceManagementMapper;
import org.jeecg.modules.PriceSystemModule.service.PriceManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;

@Service
public class PriceManagementServiceImpl implements PriceManagementService {

    @Autowired
    PriceManagementMapper mapper;

    /*
    查询所有的售价
     */
    @Override
    public IPage<PriceSystemEntity> getpriceSystemList(Page<PriceSystemEntity> page, Integer category, Integer businessType,String queryStatus) {
        IPage<PriceSystemEntity> pageList = mapper.getpriceSystemList(page, category, businessType,queryStatus);
        if (pageList != null)
            for (int i = 0; i < pageList.getRecords().size(); i++) {
                String[] fuleiId = pageList.getRecords().get(i).getTopid().split(",");
                String parentName = "";
                for (int j = 0; j < fuleiId.length; j++) {
                    if (j == 0)
                        parentName = parentName + mapper.getpartentNameBytopId(fuleiId[j]);
                    if (j > 0)
                        parentName = parentName + "," + mapper.getpartentNameBytopId(fuleiId[j]);
                }
                pageList.getRecords().get(i).setParentName(parentName);
            }
        return pageList;
    }

    //查询这个价格体系的所有区间数据
    @Override
    public List<PriceInervalEntity> getpriceInervallist(String priceSystemId) {
        return mapper.getpriceInervallist(priceSystemId);
    }

    //删除某条区间数据
    @Override
    public int deletepriceInerval(int id) {
        return mapper.deletepriceInerval(id);
    }

    //添加一条价格体系区间数据
    @Override
    public int addpriceInerval(PriceInervalEntity entity) {
        entity.setCreateTime(new Date());
        return mapper.addpriceInerval(entity);
    }


    //为价格体系添加完区间数据后修改它的状态为已设置
    @Override
    public void updatestatus(String priceSystemId) {
        mapper.updatestatus(Integer.parseInt(priceSystemId));
    }

    //判断这个体系的这个区间是否已经存在
    @Override
    public String judgeoldcz(String priceSystemId, int minNumbers, int maxNumbers) {
        return mapper.judgeoldcz(priceSystemId, minNumbers, maxNumbers);
    }

    @Override
    public List<PriceInervalEntity> getPriceInervalEntitylist(String priceSystemId) {
        return mapper. getPriceInervalEntitylist( priceSystemId);
    }
}
